
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class KusenetApplication {

	public static void main(String[] args) {
		String unioncodeStr = "&#x53EF;&#x4EE5;";
		String pattern1 = "(\\\\u(\\p{XDigit}{4}))";
		String pattern2 = "(\\\\u(\\p{XDigit}{4});)";
		unioncodeStr = unioncodeStr.replaceAll("&#x", "\\\\u");
		String result1 = KusenetApplication.unicodeToString(unioncodeStr, pattern1);
		String result2 = KusenetApplication.unicodeToString(unioncodeStr, pattern2);
		
		System.out.println("pattern:["+pattern1+"]"+" >>>>>>> transfer result string : "+result1);
		System.out.println("pattern:["+pattern2+"]"+" >>>>>>> transfer result string : "+result2);
	}
	public static String unicodeToString(String str, String patternStr) {  
	    Pattern pattern = Pattern.compile(patternStr);  
	    Matcher matcher = pattern.matcher(str);  
	    char ch;  
	    while (matcher.find()) {  
	        //group 6728  
	        String group = matcher.group(2);  
	        //ch:'木' 26408  
	        ch = (char) Integer.parseInt(group, 16);  
	        //group1 \u6728  
	        String group1 = matcher.group(1);  
	        str = str.replace(group1, ch + "");  
	    }  
	    return str;  
	}  
}
